package com.bit.librarymanagementsystem.model;

import com.bit.librarymanagementsystem.enums.ResultCode;
import lombok.Data;

@Data
public class Result <T>{
    private ResultCode code;// 200-成功 -1-未登录 -2-异常 (业务状态码)
    private String errMsg;
    private T data;

    public static <T> Result <T> success(T data){
        Result result=new Result<>();
        result.setCode(ResultCode.SUCCESS);
        result.setData(data);
        return result;
    }

    public static Result unLogin(){
        Result result=new Result();
        result.setCode(ResultCode.UNLOGIN);
        result.setErrMsg("未登录");
        return result;
    }

    public static<T> Result<T> unLogin(T data){
        Result result=new Result();
        result.setCode(ResultCode.UNLOGIN);
        result.setData(data);
        result.setErrMsg("未登录");
        return result;
    }

    public static <T> Result<T> fail(String errMsg){
        Result result = new Result<>();
        result.setCode(ResultCode.FAIL);
        result.setErrMsg(errMsg);
        return result;
    }

}
